
import zhipuai

zhipuai.api_key = "41805a5412196acfdd9d63a905f9039a.Z0TWy2173NoP1ZkI"
response = zhipuai.model_api.sse_invoke(
    model="chatglm_lite",
    prompt= [{"role":"user","content":"请用鲁迅体写一段20字左右的情书，表达对心仪对象的思念之情。请注意，鲁迅体风格的要点如下：\n经常使用短语、短句进行叙述。如“我大抵是...”，“没由来的”，“横竖都....”，”一个...，另一个...“,\"黯黯然看着.."}],
    temperature= 0.9,
    top_p= 0.7,
    incremental=True
)

for event in response.events():
    if event.event == "add":
        print(event.data, end="")
    elif event.event == "error" or event.event == "interrupted":
        print(event.data, end="")
    elif event.event == "finish":
        print(event.data)
        print(event.meta, end="")
    else:
        print(event.data, end="")